package com.ostrich.note.room;

import com.ostrich.note.App;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;


@Database(entities = {Note.class},version = 1,exportSchema = false)
public abstract class AppDataBase extends RoomDatabase {

    public static final String DB_NAME = "note.db";//数据库的名字
    //注意构造不能私有化:单例
    private static AppDataBase appDataBase;
    public static AppDataBase getInstance(){//返回当前实例对象
        if(appDataBase == null){
            synchronized (AppDataBase.class){
                if(appDataBase == null){
                    appDataBase = Room.databaseBuilder(App.instance,AppDataBase.class,DB_NAME)
                            .allowMainThreadQueries()//默认不能在主线程中访问数据库
                            .build();
                }
            }
        }
        return appDataBase;
    }

    private NoteDao mNoteDao;
    //模板模式
    public abstract NoteDao getNoteDao();




}
